#ifndef STATUSBAR_H
#define STATUSBAR_H

#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
#include <QEvent>
#include <QPoint>
#include <QRect>
#include <QTimer>
#include <QTime>
#include <QProgressBar>
#include <QLabel>
#include <QShortcut>
#include "utils/xatom-helper.h"
#include "recordingwidget.h"
#include "utils/systemnotification.h"
#include "global/global.h"
#include "utils/desktopinfo.h"
#include "customprogressbar.h"
#include <libkydatacollect.h>
#include <kborderlessbutton.h>

enum HIDEPOSATION//隐藏位置
{
    HP_None = 0,
    HP_Top = 1,
    HP_Left = 2,
    HP_Right = 3
};

class StatusBar : public QWidget
{
    Q_OBJECT
public:
    explicit StatusBar(uint qId = 0, QWidget *parent = nullptr);
    void setRecordingWid(QRect rect, uint winId);
    void setRecordingStart();
    void setMicStatus(bool isOpenMic);
    void openMicIcon(bool isOpenMic);
    void micIconGrayout(bool isOpenMic);

    void slotUpdateVolume(int newVolume);
    void slotStopRecAndSave();              //状态栏-停止录制
    void slotPauseOrResumeRec();            //状态栏-暂停/继续
    void slotCloseMicrophone();             //状态栏-开启/关闭麦克风
    void setQId(uint qId);
signals:
    void setFontSizeSignal(int); //字体变化

protected:
    void keyPressEvent(QKeyEvent * e) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void enterEvent(QEvent *event) override;
    void leaveEvent(QEvent *event) override;
    void moveEvent(QMoveEvent *event) override;
private slots:

//    void slotCloseMicrophone();
    void slotSavedSucceed(bool isSavedSucceed);
    void slotUpdateRecordingTime();

Q_SIGNALS:
    void sigCloseRec();
    void sigPauseRec();
    void sigContinueRec();

private:
    void initLayout();
    void initConnect();

    void setBtnSize();
    void setBtnIconSize();
    void setBtnIcon();
    void setTooltips();

    //主题和字体变化
    void initGsetting();
    void changeStyle();
    void initFontSize();
    void lable2SetFontSizeSlot(int size);

    void setLevelMeter();                   //设置音量进度条

    bool isWindowInScreen(QPoint pos);
    void hideWindow();
    void showWindow();
    void checkWindowPosChange();

    QWidget * m_statusWid = nullptr;
    CustomProgressBar * m_progressBar = nullptr; //CustomProgressBar
    RecordingWidget *m_recordingWid;        //录制框
    DesktopInfo m_info;

    QWidget * m_btnWid;
    kdk::KBorderlessButton *m_btnPauseRec;         // 暂停/继续 pause resume
    kdk::KBorderlessButton *m_btnStopRec;          // 停止 并保存 stop
    kdk::KBorderlessButton *m_btnMicrophoneRec;    // 音量 Volume
    QGraphicsEffect *m_originGraphicsEffect;

    QLabel * m_line1 ;
    QLabel * m_TimeRec;                 //录制时间

    bool m_isPaused = false;            //已暂停
    bool m_isClosedMicrophone = false;  //已关闭麦克风
    bool m_isSavedSucceed;              //录屏文件是否保存成功

    int m_screenWidth;
    bool m_isLMousePress;
    QPoint m_relativePos;
    HIDEPOSATION m_hp;

    //更新录制时间
    QTime recordingStartTime;
    QTime totleTime;
    int totle = 0;
    QTime startTime;
    QTime pauseTime;
    QTimer * timer;
    uint m_winId;
    uint m_qId;

};

#endif // STATUSBAR_H
